package MyFile;

import java.io.File;

public class demo1 {
    private static boolean sign = false;
    public static void main(String[] args) {
        findFile("D:\\","aaa.jpg");
        if (!sign){
            System.out.println("没找到相对应的文件!!!!");
        }
    }

    public static void findFile(String path, String name){
        if (path == null || name == null){
            return;
        }

        File file = new File(path);
        if (!file.exists() || file.isFile()){
            return;
        }

        File[] files = file.listFiles();
        if (files == null){
            return;
        }

        for (int i = 0; i < files.length; i++) {
            File tempFile = files[i];
            if (tempFile.isFile()){
                if (tempFile.getName().equals(name)){
                    System.out.println("找到该对应的文件了 ==> " + tempFile.getAbsolutePath());
                    sign = true;
                    return;
                }
            }else {
                findFile(tempFile.getAbsolutePath(),name);
            }
        }
    }
}
